package com.itheima.web.controller;

import com.github.pagehelper.PageInfo;
import com.itheima.pojo.Student;
import com.itheima.service.StuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("stu")
public class StuController {

    @Autowired
    private StuService stuService;

    @PostMapping ("findAll")
    public PageInfo<Student> findAll(@RequestParam(value = "pageNum",required = false,defaultValue = "1") Integer pageNum,
                                     @RequestParam(value = "pageSize",required = false,defaultValue = "5") Integer pageSize){
        List<Student> studentList = stuService.findAll(pageNum,pageSize);
        PageInfo<Student> pageInfo=new PageInfo(studentList);
        return pageInfo;
    }
    @PostMapping("save")
    public void save(@RequestBody Student student){
        stuService.save(student);

    }
    @GetMapping("delete")
    public void delete(Student student){
        stuService.delete(student);

    }
    @PostMapping("update")
    public void update(@RequestBody Student student){
        stuService.update(student);

    }

}
